define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zizhudaochu/index' + location.search,
                    // add_url: 'zizhudaochu/add',
                    // edit_url: 'zizhudaochu/edit',
                    // del_url: 'zizhudaochu/del',
                    // multi_url: 'zizhudaochu/multi',
                    // import_url: 'zizhudaochu/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'shipping_contact', title:'name', operate: 'LIKE'},
                        {field: 'shipping_idcard', title: __('idcard'), operate: 'LIKE'},
                        {
                            field: 'shipping_province',
                            title: __('post_area'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: function (value, row, index) {
                                str = value + "-" + row.shipping_city +"-"+row.shipping_area;
                                return str;
                            }
                        },

                        {
                            field: 'shipping_address',
                            title: __('post_address'),
                            operate: 'LIKE',
                            table: table, class: 'autocontent'
                        },
                        {field: 'shipping_phone', title: __('post_phone'), operate: 'LIKE'},
                        {
                            field: 'phone_area',
                            title: __('phone_area'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                        },
                        {field: 'phone_buy', title: __('phone_buy'), operate: 'LIKE'},
                        {field: 'code', title: 'code', operate: 'LIKE'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
